# Project properties
cmake_minimum_required(VERSION 3.8)
project(benchmark)

include(ExternalProject)

find_library(GLOG_LIBRARIES NAMES glog REQUIRED)
find_library(TCMALLOC NAMES tcmalloc REQUIRED)
find_library(VMEM_LIBRARY NAMES vmem REQUIRED)

if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE "Release")
endif()


set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -pthread -fmax-errors=5")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -fmax-errors=5 -DDNSDEBUG")

message("${CMAKE_BUILD_TYPE}")

ExternalProject_Add (
    YCSB-Gen
    GIT_REPOSITORY "https://gitee.com/ypluo18/YCSB-Gen.git"
    GIT_TAG "master"
    UPDATE_COMMAND ""
    INSTALL_COMMAND ""
    LOG_DOWNLOAD ON
    LOG_CONFIGURE ON
    LOG_BUILD ON
)

add_subdirectory(dnskv)
add_subdirectory(myslm)
add_subdirectory(btree)

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    set(ROCKSDB_LIB librocksdb_debug.so)
else()
    set(ROCKSDB_LIB librocksdb.so)
endif()

# 添加matrixkv编译目标
add_custom_target(build_matrixkv ALL
        COMMAND make DISABLE_WARNING_AS_ERROR=true shared_lib
        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/matrixkv/
        COMMENT "matrixkv compile target")
set(MATRIX_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/matrixkv/${ROCKSDB_LIB})

link_libraries(${MATRIX_LIBRARY})
link_libraries(${NOVELSM_LIBRARY})

include_directories(matrixkv/include)
include_directories(novelsm/include)
include_directories(myslm)
include_directories(btree)

add_executable(benchmark benchmark.cc) 
add_dependencies(benchmark build_matrixkv)
target_link_libraries(benchmark tcmalloc glog dnskv myslm nsbtree)